<?php
	/*
		CMA Version: 1.0
		Developed by: Eduetech.com
	*/

	require_once("includes/config.php");

if ($_SESSION['User']  || $_SESSION['User']-rid)
{

	//$smarty->assign('error',$msg_mustlogin);
	$smarty->display(userdashboard($_SESSION['User']));
	exit;
} 
	//Forms posted
	if(!empty($_POST))
	{
			$_SESSION['User']=null;
			$errors = array();
			$username = trim($_POST["username"]);
			$password = trim($_POST["password"]);
			
			
			//Perform some validation
			//Feel free to edit / change as required
			if($username == "" || $password == "")
			{
				$smarty->assign('error','Invalid user name or password !');
				$smarty->display('tpls/index.tpl');
				die();
				
			}
			
			if(!usernameExists($username,$password)){
				$smarty->assign('error','Invalid user name or password !');
				$smarty->display('tpls/index.tpl');
				die();
			}else{
					$_SESSION['User']= getUserSessionObject($username);
					/*
					print "<pre>";
					print_r($_SESSION['User']);
					die();
					*/
					$smarty->display(userdashboard($_SESSION['User']));
					Exit;
			
				
			}
			

	
	
	}
	$smarty->display('tpls/index.tpl');
?>